package models

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"log"
	"new00/appconfig"
)

var DB *gorm.DB

func Init() {
	var err error
	mysqlconf := appconfig.AppConf.Mysql
	dsn := fmt.Sprintf("user:pass@tcp(127.0.0.1:3306)/dbname?charset=utf8mb4&parseTime=True&loc=Local", mysqlconf.User, mysqlconf.Password, mysqlconf.Host, mysqlconf.Port, mysqlconf.Database)
	DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		panic(err)
	}
	log.Println("数据库连接成功")
}
